// 将十六进制颜色转换为 RGB 数组
function hexToRgb(hex){
	return [
		parseInt(hex.slice(1, 3), 16),
		parseInt(hex.slice(3, 5), 16),
		parseInt(hex.slice(5, 7), 16),
	];
}

// 将 RGB 数组转换回十六进制颜色
function rgbToHex([r, g, b]){
	return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase()}`;
}

// 生成浅色的算法
function generateLighterColor(hexColor, lightenFactor = 0.7){
	const rgb = hexToRgb(hexColor);

    // 每个通道增加 lightenFactor，使颜色变浅
	const lighterRgb = rgb.map((channel) => {
		const newChannel = Math.round(channel + (255 - channel) * lightenFactor);
		return Math.min(255, newChannel); // 确保值不超过 255
	});

	return rgbToHex(lighterRgb);
}
export default generateLighterColor;